package swings.labels;

import swings.panels.WorkPanel;
import utils.CommonUtils;
import utils.ImageUtils;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

/**
 * @version V1.0
 * @Title:
 * @Package
 * @Description:
 * @author: runoob
 * @date:
 */
public class HeaderLabel extends JLabel {

    private JLabel keyLabel = new JLabel();
    private JLabel valueLabel = new JLabel();
    private JLabel descriptionLabel = new JLabel();
    public String key;
    public String value;
    public String description;

    public HeaderLabel(int y, String key, String value, String description) throws IOException {
        this.key = key;
        this.value = value;
        this.description = description;
        setParamLabel(y);
    }

    public HeaderLabel(int y, String key, String value) throws IOException {
        this.key = key;
        this.value = value;
        setResponseLabel(y);
    }

    private void setParamLabel(int y) throws IOException {

        Font font = CommonUtils.getFont();
        int width = WorkPanel.width-90;
        this.setIcon(ImageUtils.common);
        this.setVerticalTextPosition(JLabel.CENTER);
        this.setHorizontalTextPosition(JLabel.CENTER);
        this.setFont(font);
        this.setForeground(Color.WHITE);
        this.setBounds(5,y,WorkPanel.width-20,30);
        keyLabel.setText(key);
        keyLabel.setFont(font);
        keyLabel.setForeground(Color.WHITE);
        keyLabel.setBounds(40,0,width/3-5,30);
        keyLabel.setBackground(Color.WHITE);
        valueLabel.setText(value);
        valueLabel.setFont(font);
        valueLabel.setForeground(Color.WHITE);
        valueLabel.setBounds(40 + width/3,0,width/3-5,30);
        valueLabel.setBackground(Color.WHITE);
        descriptionLabel.setText(description);
        descriptionLabel.setFont(font);
        descriptionLabel.setForeground(Color.WHITE);
        descriptionLabel.setBounds(40 + width*2/3,0,width/3-5,30);
        descriptionLabel.setBackground(Color.WHITE);

        this.add(keyLabel);
        this.add(valueLabel);
        this.add(descriptionLabel);
        this.add(new BarLabel(32,1));
        this.add(new BarLabel(32 + width/3,1));
        this.add(new BarLabel(32 + width*2/3,1));
        this.add(new BarLabel(32 + width,1));
//        this.add(bg);

    }

    private void setResponseLabel(int y) throws IOException {

        Font font = CommonUtils.getFont();
        int width = WorkPanel.width-90;
        this.setIcon(ImageUtils.common);
        this.setVerticalTextPosition(JLabel.CENTER);
        this.setHorizontalTextPosition(JLabel.CENTER);
        this.setFont(font);
        this.setForeground(Color.WHITE);
        this.setBounds(5,y,WorkPanel.width-20,30);
        keyLabel.setText(key);
        keyLabel.setFont(font);
        keyLabel.setForeground(Color.WHITE);
        keyLabel.setBounds(40,0,width/2-5,30);
        keyLabel.setBackground(Color.WHITE);
        valueLabel.setText(value);
        valueLabel.setFont(font);
        valueLabel.setForeground(Color.WHITE);
        valueLabel.setBounds(40 + width/2,0,width/2-5,30);
        valueLabel.setBackground(Color.WHITE);

        this.add(keyLabel);
        this.add(valueLabel);
        this.add(new BarLabel(32,1));
        this.add(new BarLabel(32 + width/2,1));
        this.add(new BarLabel(32 + width,1));
//        this.add(bg);

    }

}

